<template>
  <Form :data="model" @ok="onOk" :col="1">
    <FormItem field="printStatus" title="发票状态" required>
      <Enum component="Radio" clazz="PrintStatus" v-model="model.printStatus" :filter="filter" />
    </FormItem>
    <template #op>
      <ModalButton :loading="okaying" />
    </template>
  </Form>
</template>
<script setup>
import { Enum, Form, FormItem, ModalButton } from '@idmy/ui'
import { Message, Modal, useLoading } from '@idmy/core'
import { reactive } from 'vue'
import { updateStatus } from './services'

const props = defineProps({
  id: { type: Number, required: true },
})

const model = reactive({
  id: props.id,
})

const [onOk, okaying] = useLoading(async () => {
  await updateStatus(model.id, model.printStatus)
  Message.success('保存成功')
  Modal.ok()
})

const filter = item => ['NONE', 'PRINTED'].includes(item.key)
</script>
